package com.xsq.util;

import com.common.utils.LogUtils;

public class M1Card {

	public static String getCardno(byte[] block_48) {

		String card_prefix = leftZere(toHexStr(block_48[7]), 2);
		String card_suffix = leftZere(toHexStr(block_48[2]), 2) + "" + leftZere(toHexStr(block_48[9]), 2) + leftZere(toHexStr(block_48[0]), 2);
		return Integer.parseInt(card_prefix, 16) + "" + Integer.parseInt(card_suffix, 16);
	}

	public static String leftZere(String s, int length) {
		if (s.length() >= length) {
			return s.substring(0, length);
		} else {
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < length - s.length(); i++) {
				sb.append("0");
			}
			sb.append(s);
			return sb.toString();
		}
	}

	public static String reverseOrder(String sn) {
		if (sn.length() % 2 != 0) {
			LogUtils.info("高低字节转化数据不对");
			return sn;
		}
		StringBuffer buf = new StringBuffer();
		for (int i = sn.length() / 2 - 1; i >= 0; i--) {
			buf.append(sn.substring(2 * i, 2 * i + 2));

		}
		return buf.toString();
	}

	public static String toHexStr(int n) {
		return Integer.toHexString(n < 0 ? n + 256 : n);
	}
}
